package com.zbkj.crmeb.merchant.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.enums.ProductTypeEnum;
import com.zbkj.crmeb.store.model.StoreBannerSetUp;
import com.zbkj.crmeb.store.request.StoreProductSearchRequest;
import com.zbkj.crmeb.store.response.StoreProductResponse;
import com.zbkj.crmeb.store.service.StoreBannerSetUpService;
import com.zbkj.crmeb.store.service.StoreModuleSetUpService;
import com.zbkj.crmeb.store.service.StoreProductSelectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "商品精选")
@RequestMapping("/api/admin/mer/product/selection")
public class StoreProductSelectionController extends AdminBaseController{

    @Autowired
    private StoreProductSelectionService storeProductSelectionService;
    @Autowired
    StoreBannerSetUpService storeBannerSetUpService;
    @Autowired
    StoreModuleSetUpService storeModuleSetUpService;

    @ApiOperation("获取库存深度/昨日热销/近30天热销/搜索页")
    @GetMapping
    public CommonResult<CommonPage<StoreProductResponse>> getList(StoreProductSearchRequest request, PageParamRequest pageParamRequest, HttpServletRequest servletRequest){
        List<Integer> isNotEurope = Arrays.asList(ProductTypeEnum.INSIDE.getCode());
        request.setIsNotEurope(isNotEurope);
        return CommonResult.success(CommonPage.restPage(storeProductSelectionService.getMerchnatList(request, pageParamRequest, getMerId(servletRequest))));
    }

    @ApiOperation("获取banner详情")
    @GetMapping("/banner/{bannerId}")
    public CommonResult<Map<String, Object>> getBannerDetail(@PathVariable Integer bannerId, PageParamRequest pageParamRequest, HttpServletRequest request){
        return CommonResult.success(storeProductSelectionService.getBannerDetails(bannerId, pageParamRequest, getMerId(request)));
    }

    @ApiOperation("获取模块详情")
    @GetMapping("/module/{moduleId}")
    public CommonResult<Map<String, Object>> getModuleDetail(@PathVariable Integer moduleId, PageParamRequest pageParamRequest){
        return CommonResult.success(storeProductSelectionService.getModuleDetails(moduleId, pageParamRequest));
    }

    @ApiOperation("上架商品")
    @PutMapping("/info/{productId}")
    public CommonResult<Object> putOnShelves(@PathVariable Integer productId, HttpServletRequest request){
        String token = checkAdminToken.getTokenFormRequest(request);
        return CommonResult.success(storeProductSelectionService.putOnShelves(token, productId));
    }

    @ApiOperation("商品详情")
    @GetMapping("/info/{productId}")
    public CommonResult<Map<String, Object>> getProductInfo(@PathVariable Integer productId, HttpServletRequest request){
        return CommonResult.success(storeProductSelectionService.getProductInfo(productId, getMerId(request)));
    }

    @ApiOperation("为你推荐")
    @GetMapping("/recommend")
    public CommonResult<CommonPage<StoreProductResponse>> recommendToYou(PageParamRequest request, HttpServletRequest servletRequest){
        return CommonResult.success(CommonPage.restPage(storeProductSelectionService.recommendToYou(request, getMerId(servletRequest))));
    }

    /**
     * banner列表
     * @Description:
     * @author duyb
     * @return CommonResult<Object>
     * @Date: 2022-11-15
     */
    @ApiOperation(value = "列表")
    @GetMapping("/banner/list")
    public CommonResult<Object> listEntity() {
        return CommonResult.success(storeBannerSetUpService.list(Wrappers.<StoreBannerSetUp>lambdaQuery()
                .eq(StoreBannerSetUp :: getIsShow, true)
                .orderByAsc(StoreBannerSetUp :: getSort)
                .orderByAsc(StoreBannerSetUp :: getCreateTime)
        ));
    }


    /**
     * 模块列表
     * @Description:
     * @author duyb
     * @return CommonResult<Object>
     * @Date: 2022-11-15
     */
    @ApiOperation(value = "列表")
    @GetMapping("/module/list")
    public CommonResult<Object> getList() {
        return CommonResult.success(storeModuleSetUpService.getList());
    }
}
